package com.financing.platform.dao.impl;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.financing.platform.dao.IProductRecommendDao;
import com.financing.platform.dto.ProductRecommendDTO;
import com.financing.platform.util.SqlName;
import com.financing.platform.vo.EmailTemplateProjectVO;

@Repository("productRecommendDaoImpl")
public class ProductRecommendDaoImpl extends BaseDaoImpl implements
		IProductRecommendDao {

	public Integer addProductRecommend(ProductRecommendDTO productRecommendDto) {
		try {
			this.sqlMapClient.insert(SqlName.addProductRecommend, productRecommendDto);
			return 1;
		} catch (SQLException e) {
			log.error("Add product recommend error:",e);
			return 0;
		}
	}

	@SuppressWarnings("unchecked")
	public List<ProductRecommendDTO> queryProductRecommendList(
			ProductRecommendDTO productRecommendDto) {
		 try {
			return this.sqlMapClient.queryForList(SqlName.queryRecommendList, productRecommendDto);
		} catch (SQLException e) {
			log.error("Query product recommend info error!",e);
			return Collections.emptyList();
		}
	}

	public int deleteProductRecommend(ProductRecommendDTO productRecommendDto) throws SQLException {
		return this.sqlMapClient.delete(SqlName.deleteRecommend,productRecommendDto);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<EmailTemplateProjectVO> getEmailTemplateProjectList(
			Integer limit) throws SQLException {
		return this.sqlMapClient.queryForList(SqlName.queryEmailProjectRecommendList,limit);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<EmailTemplateProjectVO> queryEmailProjectList(Integer limit)
			throws SQLException {
		return this.sqlMapClient.queryForList(SqlName.queryEmailProjectList,limit);
	}

}
